﻿using LitJson;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OCR.Config
{
    internal class LocalInfo
    {
        //CameraParam_Config
        public static string Exposure;//曝光  500
        public static string Gain;//增益  0
        public static string FrameRate;//帧率  57.6
        public static string PixelFormat;//像素格式  Mono8

        //Motor_Config
        public static string usAxis;      //轴号  0  ushort
        public static string dStartVel;           //起始速度  100  double
        public static string dMaxVel;             //运行速度  10000  double
        public static string dTacc;               //加速时间  0.5  double
        public static string dTdec;               //减速时间  0.5  double
        public static string dStopVel;          //停止速度  100  double
        public static string dSpara;          //S段时间    0.2     double
        public static string usDir;       //运动方向  1 ushort

        //CameraTriggerTime_Config
        public static string CameraTrigger_Delay = "10";//延迟时间
        public static string CameraTrigger_Time = "30";//触发提供时间

        //NGTime_Config
        public static string NG_Delay = "10";//吹气时间
        public static string NG_Action = "50";//延迟时间

        public static void  LocalInfoInitial() 
        {
            CameraParam_Config cameraParam_Config = new CameraParam_Config();
            StreamReader sr = new StreamReader("Config\\CameraParam_Config.json");
            string re = sr.ReadToEnd();
            cameraParam_Config = JsonMapper.ToObject<CameraParam_Config>(re);
            Exposure= cameraParam_Config.Exposure;
            Gain= cameraParam_Config.Gain;
            FrameRate= cameraParam_Config.FrameRate;
            PixelFormat= cameraParam_Config.PixelFormat;

            Motor_Config motor_Config = new Motor_Config();
            sr = new StreamReader("Config\\Motor_Config.json");
            string re1 = sr.ReadToEnd();
            motor_Config = JsonMapper.ToObject<Motor_Config>(re1);
            usAxis=motor_Config.usAxis;
            dStartVel = motor_Config.dStartVel;
            dMaxVel=motor_Config.dMaxVel;
            dTacc=motor_Config.dTacc;
            dTdec=motor_Config.dTdec;
            dStopVel=motor_Config.dStopVel;
            dSpara=motor_Config.dSpara;
            usDir=motor_Config.usDir;

            CameraTriggerTime_Config cameraTriggerTime_Config = new CameraTriggerTime_Config();
            sr = new StreamReader("Config\\CameraTriggerTime_Config.json");
            string re2 = sr.ReadToEnd();
            cameraTriggerTime_Config = JsonMapper.ToObject<CameraTriggerTime_Config>(re2);
            CameraTrigger_Delay=cameraTriggerTime_Config.CameraTrigger_Delay;
            CameraTrigger_Time=cameraTriggerTime_Config.CameraTrigger_Time;

            NGTime_Config nGTime_Config = new NGTime_Config();
            sr = new StreamReader("Config\\NGTime_Config.json");
            string re3 = sr.ReadToEnd();
            nGTime_Config = JsonMapper.ToObject<NGTime_Config>(re3);
            NG_Delay=nGTime_Config.NG_Delay;
            NG_Action=nGTime_Config.NG_Action;
            //Console.WriteLine("NG_Delay:-----" + NG_Delay);
            //Console.WriteLine("NG_Action:-----" + NG_Action);
            sr.Close();
        }

        public static void CameraParam_Config_InfoUpdate(string Exposure, string Gain)
        {
            CameraParam_Config cameraParam_Config = new CameraParam_Config();
            cameraParam_Config.Exposure = Exposure;
            string json=JsonMapper.ToJson(cameraParam_Config);

            File.WriteAllText("Config\\CameraParam_Config.json", json, Encoding.UTF8);
        }

        public static void OutImgPath_Config_InfoUpdate()
        {
            OutImgPath_Config outImgPath_Config = new OutImgPath_Config();
            outImgPath_Config.OutPath = outImgPath;
            string json = JsonMapper.ToJson(outImgPath_Config);

            File.WriteAllText("Config\\OutImgPathConfig.json", json, Encoding.UTF8);
        }

        public static void DeleteDay_Config_InfoUpdate()
        {
            DeleteDay_Config deleteDay_Config = new DeleteDay_Config();
            deleteDay_Config.DeleteDay = deleteDay.ToString();
            string json = JsonMapper.ToJson(deleteDay_Config);

            File.WriteAllText("Config\\DeleteDayConfig.json", json, Encoding.UTF8);
        }
        public static void DI_Interval_Config_InfoUpdate()
        {
            DI_Interval_Config dI_Interval = new DI_Interval_Config();
            dI_Interval.DI_Interval = DI_Interval.ToString();
            string json = JsonMapper.ToJson(dI_Interval);

            File.WriteAllText("Config\\DI_IntervalConfig.json", json, Encoding.UTF8);
        }

        public static void isLOG_Config_InfoUpdate()
        {
            isLOG_Config isLOG_Config = new isLOG_Config();
            isLOG_Config.isLog = isLog;
            string json = JsonMapper.ToJson(isLOG_Config);

            File.WriteAllText("Config\\IsLOG_Config.json", json, Encoding.UTF8);
        }

        public static void ProductCount_Config_InfoUpdate()
        {
            ProductCountConfig productCountConfig = new ProductCountConfig();
            productCountConfig.totalCount = totalCount.ToString();
            productCountConfig.ngCount = ngCount.ToString();
            string json = JsonMapper.ToJson(productCountConfig);

            File.WriteAllText("Config\\ProductCount_Config.json", json, Encoding.UTF8);
        }
        public static void Tem_RectMaxCount_Config_InfoUpdate()
        {
            Tem_RectMaxCount_Config tem_RectMaxCount_Config = new Tem_RectMaxCount_Config();
            tem_RectMaxCount_Config.Tem_RectMaxCount = Tem_RectMaxCount.ToString();
            string json = JsonMapper.ToJson(tem_RectMaxCount_Config);

            File.WriteAllText("Config\\Tem_RectMaxCount_Config.json", json, Encoding.UTF8);
        }
        public static void Tem_ImgPath_Config_InfoUpdate()
        {
            TemplateImgPathConfig templateImgPathConfig = new TemplateImgPathConfig();
            templateImgPathConfig.TemplateImgPath = Tem_ImgPath;
            string json = JsonMapper.ToJson(templateImgPathConfig);

            File.WriteAllText("Config\\TemplateImgPathConfig.json", json, Encoding.UTF8);
        }
        public static void CameraSerialNumber_Config_InfoUpdate()
        {
            CameraSerialNumber_Config cameraSerialNumber_Config = new CameraSerialNumber_Config();
            cameraSerialNumber_Config.CameraSerialNumber = CameraSerialNumber;
            string json = JsonMapper.ToJson(cameraSerialNumber_Config);

            File.WriteAllText("Config\\CameraSerialNumber_Config.json", json, Encoding.UTF8);
        }
        public static void NgOrOkSignal_Config_InfoUpdate()
        {
            NgOrOkSignal_Config ngOrOkSignal_Config = new NgOrOkSignal_Config();
            ngOrOkSignal_Config.NgOrOkSignal = ngOrOkSignal;
            string json = JsonMapper.ToJson(ngOrOkSignal_Config);

            File.WriteAllText("Config\\NgOrOkSignal_Config.json", json, Encoding.UTF8);
        }
        public static void CloseSignalDelayTime_Config_InfoUpdate()
        {
            CloseSignalDelayTime_Config closeSignalDelayTime = new CloseSignalDelayTime_Config();
            closeSignalDelayTime.CloseSignalDelayTime = CloseSignalDelayTime;
            string json = JsonMapper.ToJson(closeSignalDelayTime);

            File.WriteAllText("Config\\CloseSignalDelayTime_Config.json", json, Encoding.UTF8);
        }
        public static void NGControlType_Config_InfoUpdate()
        {
            NGControlType_Config nGControlType_Config = new NGControlType_Config();
            nGControlType_Config.NGControlType = NGControlType;
            string json = JsonMapper.ToJson(nGControlType_Config);

            File.WriteAllText("Config\\NGControlType_Config.json", json, Encoding.UTF8);
        }
        public static void RepeatSignalCheckTime_Config_InfoUpdate()
        {
            RepeatSignalCheckTime_Config repeatSignalCheckTime_Config = new RepeatSignalCheckTime_Config();
            repeatSignalCheckTime_Config.RepeatSignalCheckTime = RepeatSignalCheckTime;
            string json = JsonMapper.ToJson(repeatSignalCheckTime_Config);

            File.WriteAllText("Config\\RepeatSignalCheckTime_Config.json", json, Encoding.UTF8);
        }
        public static void isOKRect_Config_InfoUpdate()
        {
            isOKRect_Config isOKRect_Config = new isOKRect_Config();
            isOKRect_Config.isOKRect = isOKRect;
            string json = JsonMapper.ToJson(isOKRect_Config);

            File.WriteAllText("Config\\isOKRect_Config.json", json, Encoding.UTF8);
        }
        public static void CheckDI_Config_InfoUpdate()
        {
            CheckDI_Config checkDI_Config = new CheckDI_Config();
            checkDI_Config.CheckDI = CheckDI;
            string json = JsonMapper.ToJson(checkDI_Config);

            File.WriteAllText("Config\\CheckDI_Config.json", json, Encoding.UTF8);
        }
        public static void isSaveOK_Config_InfoUpdate()
        {
            isSaveOK_Config isSaveOK_Config = new isSaveOK_Config();
            isSaveOK_Config.isSaveOK = isSaveOK;
            string json = JsonMapper.ToJson(isSaveOK_Config);

            File.WriteAllText("Config\\isSaveOK_Config.json", json, Encoding.UTF8);
        }
        public static void isSaveNG_Config_InfoUpdate()
        {
            isSaveNG_Config isSaveNG_Config = new isSaveNG_Config();
            isSaveNG_Config.isSaveNG = isSaveNG;
            string json = JsonMapper.ToJson(isSaveNG_Config);

            File.WriteAllText("Config\\isSaveNG_Config.json", json, Encoding.UTF8);
        }

        public static void ProductConfigListName_Config_InfoUpdate()
        {
            ProductConfigListName_Config ProductConfigListName_Config = new ProductConfigListName_Config();
            ProductConfigListName_Config.ProductConfigListName = ProductConfigListName;
            string json = JsonMapper.ToJson(ProductConfigListName_Config);

            File.WriteAllText("Config\\ProductConfigListName_Config.json", json, Encoding.UTF8);
        }

        public static float imgScale = 1;

        public static int totalCount = 0;//连续计数
        public static int ngCount = 0;//ng计数
        public static int currCount = 0;//启动后本次运行物料计数

        public static int deleteDay = 0;

        public static string outImgPath;

        public static DateTime lastDI_DT;

        public static int PermissionIndex;


        public static string DI_Interval;

        public static string isLog; //0为记录日志  

        public static List<int> wrongIndex = new List<int>();

        public static int Tem_RectMaxCount;

        public static string Tem_ImgPath;

        public static List<string> wrongString = new List<string>();

        public static string CameraSerialNumber;//相机序列号

        public static string CameraStateResult;//相机断线结果

        //授权公钥
        public static string PublicKey=
            "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCmXsT7fxmz4sKAVIgNjUe5ulTveodnyMuPBqkBmj1aN7yUojbAhhUn0pNMAWlZhf5BzKy7DROSlcFIONt8MZ9505xRdFEUsFHhlFxLsf9ygRMMNJ8XZ1mD7NC8Gq6ee8YOpNg9CJK/5WFOurM1QWW8si+wGvMzGjd3wVH7orgrEwIDAQAB";

        public static bool isAuthorization = false;  //授权

        public static string ngOrOkSignal;//ng发送信号还是ok发送信号

        public static string isStartRun;//是否开机启动流程

        public static string CloseSignalDelayTime;//关闭NG信号延迟时间

        public static string NGControlType;//是否自检NG踢料  0为自检踢料

        public static string RepeatSignalCheckTime;//DI重复杂讯监测时间

        public static string isOKRect;//是否画OK的框  0为不画框  

        public static string CheckDI;//是否监测DI信号  0为不监测

        public static string isSaveOK;//是否保存OK图

        public static string isSaveNG;//是否保存NG原图

        public static string currState;//当前DI状态
        public static string lastState;//上次DI状态 用于判断是否DI重复触发  当上次DI为0当前DI为1时才进行拍照逻辑

        public static string ProductConfigListName;//产品配置清单

        public static string DelaySingleType;//是否延迟板数  0为关闭
    }
}
